import java.util.Arrays;
import java.util.Scanner;

public class Main {
    //数组初始化
    public static void main(String[] args) {
        int[] arr = new int[10];
        Arrays.fill(arr,-1);
        System.out.println(Arrays.toString(arr));
        Arrays.fill(arr,2,5,4);
        System.out.println(Arrays.toString(arr));
    }
    //数组逆序
    public static void reverse(int[] arr){
        int left = 0,right = arr.length-1;
        while(left <= right){
            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
            left++;
            right--;
        }
    }
    public static void main2(String[] args) {
        int[]arr = {1,2,3,4,5,6,7,8,9,0};
        reverse(arr);
        System.out.println(Arrays.toString(arr));
    }
    //找到数组中元素
    /**
     * 二分查找
     */
    public static int binarySearch(int[] arr, int target) {
        int begin = 0,end = arr.length-1;
        while(begin<=end){
            int mid = (begin+end) >>> 1;
            if(arr[mid]==target){
                return mid;
            }
            else if(arr[mid]<target){
                begin = mid+1;
            }
            else{
                end = mid-1;
            }
        }
        return -1;
      /*  for(int i = begin; i <= end; i++){
            if(arr[i] == target){
                return i;
            }
            else if(arr[i]<target){
                begin = i+1;
            }
            else{
                end = i-1;
            }
        }
        return -1;*/
    }
    public static int FindArray(int[]arr,int n){
        for(int i=0;i<arr.length;i++){
            if(arr[i]==n){
                return i;
            }
        }
        return -1;
    }
    public static void main1(String[] args) {
        int[] arr= {1,2,3,4,5,6,7,8,9,0};
        Arrays.sort(arr);
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(FindArray(arr,n));
        System.out.println(binarySearch(arr,n));
    }
}